/**
 * Author@ Cheng Feitian
 * Date: 2021-3-31
 * Description: 递增运算符重载
 */

#include <algorithm>
#include <iostream>
#include <string>

using namespace std;
const int maxn = 1024;

//自定义整型
class MyInteger
{
    friend ostream & operator<<(ostream & cout,MyInteger myInteger);
private:
    int m_Num;

public:
    MyInteger(){
        m_Num = 0;
    }

    //重载前置++运算符 返回引用为了一直对一个数据进行递增操作
    MyInteger & operator++(){
        //先进行++运算
        m_Num++;
        //再将自身做返回
        return *this;
    }
    //重载后置++运算符
    //void operator++(int)  int代表占位参数，可以用于区分前置和后置递增
    MyInteger operator++(int){
        //先 记录当时结果
        MyInteger temp = *this;
        //后递增
        m_Num++;
        //最后将记录结果返回
        return temp;
    }
};

ostream & operator<<(ostream & cout,MyInteger myInteger){
    cout << myInteger.m_Num;
    return cout;
}

void test01(){
    MyInteger myint;

    cout << ++myint << endl;
}

void test02(){
    MyInteger myint;

    cout << myint++ << endl;
}

int main()
{
    test01();
    test02();
    return 0;
}
